<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="合同编号" prop="sfContractNo">
        <el-input
          v-model="queryParams.sfContractNo"
          placeholder="请输入合同编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="小区名" prop="premiseName">
        <el-input
          v-model="queryParams.premiseName"
          placeholder="请输入小区名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="业主姓名" prop="ownerName">
        <el-input
          v-model="queryParams.ownerName"
          placeholder="请输入业主姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="起租时间" prop="leaseStartTime">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.leaseStartTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择租约期限开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="到期时间" prop="leaseEndTime">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.leaseEndTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择租约期限结束时间">
        </el-date-picker>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="contractList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="合同编号" align="center" prop="sfContractNo" />
      <el-table-column label="小区" align="center" prop="premiseName" />
      <el-table-column label="业主" align="center" prop="ownerName" />
      <el-table-column label="电话" align="center" prop="ownerMobile" />
      <el-table-column label="起租日期" align="center" prop="leaseStartTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.leaseStartTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="结束日期" align="center" prop="leaseEndTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.leaseEndTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="录入日期" align="center" prop="conInfoTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.conInfoTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核日期" align="center" prop="conAudTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.conAudTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作人" align="center" prop="sfUserName" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button type="warning" plain>导入还款计划</el-button>
          <el-button type="warning" @click="getEDocument(scope.row)" plain>预览合同</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listContract,createEDocument} from "@/api/renting/contract";

export default {
  name: "Contract",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      contractList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sfContractNo: null,
        premiseName: null,
        ownerName: null,
        leaseStartTime: null,
        leaseEndTime: null,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listContract(this.queryParams).then(response => {
        this.contractList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getEDocument(row){
      createEDocument(row).then(response => {
        let a = window.btoa('http://rcdkvzv4v.hn-bkt.clouddn.com/'+response.data);
        window.open('http://43.142.33.78:8012/onlinePreview?url='+a);
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
  }
};
</script>
